package com.springlearn.springsourcecode.chap6;

import com.springlearn.springsourcecode.chap5.A05Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @author wtcode
 * @Description Aware接口及 InitializingBean接口
 * @date 2025/3/31 - 9:47
 */
public class A06Application {
    private static final Logger log = LoggerFactory.getLogger(A06Application.class);

    public static void main(String[] args) {
        // Aware用于注入一些与容器相关的信息，例如
        // BeanNameAware 注入bean的名字
        // BeanFactoryAware 注入BeanFactory容器
        // ApplicationContextAware 注入ApplicationContext容器
        // EmbeddedValueResolverAware ${}

        GenericApplicationContext context = new GenericApplicationContext();
        //context.registerBean("myBean",MyBean.class);
        //context.registerBean("myConfig1",MyConfig1.class);
        context.registerBean("myConfig2",MyConfig2.class);


        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);
        context.registerBean(CommonAnnotationBeanPostProcessor.class);
        context.registerBean(ConfigurationClassPostProcessor.class);

        context.refresh(); // 1.添加beanFactory后处理器  2.添加bean的后处理器 3.初始化单例
        context.close();



    }
}
